import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userName: "",
    userMenuNodes: [],
    editableTabsValue: '/Main/Index',
    editableTabs: [{name: '/Main/Index', title: "首页"}]
  },
  getters: {
    getUserName: (state) => {
      return state.userName;
    },
    getEditableTabsValue: (state) => {
      return state.editableTabsValue;
    },
    getEditableTabs: (state) => {
      return state.editableTabs;
    },

  },
  mutations: {
    setUserName: (state, userName) => {
      state.userName = userName;
    },
    setEditableTabsValue: (state, editableTabsValue) => {
      state.editableTabsValue = editableTabsValue;
    },
    setUserMenuNodes: (state, userMenuNodes) => {
      state.userMenuNodes = userMenuNodes;
    },
    resetEditableTabs: (state) => {
      state.editableTabs = [{name: '/Main/Index', title: "首页"}]
    },
    addEditableTab: (state, tab) => {
      if (state.editableTabs.findIndex(e => e.name === tab.name) === -1) {
        state.editableTabs.push(tab);
      }
      state.editableTabsValue = tab.name
    }

  },
  actions: {
    setUserName(context, payload) {
      context.commit("setUserName", payload); //Action提交的是mutation
    },
  }
})
